{extend name="common/base" /}
{block name="body"}
<div class="zuce-mains">
        <div class="zuce-img"><img src="__CDN__/html/img/login_logo.png"></div>
        <div class="zuce-list">
          <div class="list-input">
              <input type="hidden" name='rid' class='js-rid' value='{$rid}'>
            <input type="text" class="iput1 js-phone" placeholder="请输入11位手机号码">
            <div class="hqyz js-yzm" is_allow_click='1'>获取验证码</div>
          </div>
          <div class="list-input">
            <input type="text" class="iput1 input2 js-code" placeholder="请输入4位验证码">
          </div>
          <div class="list-input">
            <input type="password" class="iput1 input2 js-password" placeholder="请输入6-16位字母/数字">
          </div>                      
        </div>
        <div class="zc-button js-register">立即注册</div>
        <p class="zc-sf">已有账号，<i><a href="{:url('Pub/login')}">直接登录></a></i></p>
      </div>
{/block}
{block name="menu"}{/block}
{block name="script"}
<script type="text/javascript">
    $(function () {
        $('.js-register').on('click', function () {
            var phone = $('.js-phone').val();
            var password = $('.js-password').val();
            var code = $('.js-code').val();
            var rid = $('.js-rid').val();
            if (!is_mobile(phone)) {
                mui.alert('请填写正确格式手机号');
                return false;
            }
            if (!code) {
                mui.alert('请填写验证码');
                return false;
            }
            if (!password) {
                mui.alert('请填写密码');
                return false;
            }
            
            $.post("{:url('Pub/register')}", {phone: phone, password: password, code:code,rid:rid}, function (res) {
                if (res.code == '1') {
                    setTimeout(function () {
                        location.href = res.url;
                    }, 2000);
                }
                mui.toast(res.msg);
            }, 'json');

        });
        
        //发送验证码
        $('.js-yzm').click(function(){
            var phone = $('.js-phone').val();
            if (!is_mobile(phone)) {
                mui.toast('请填写正确格式手机号');
                return false;
            }
            var obj = $(this);
            if(obj.attr('is_allow_click') == 1){
                settime($(this));
                $.post("{:url('pub/sendcode')}", {phone: phone}, function (res) {
                    mui.toast(res.msg);
                }, 'json');
            }
        });
    });
    
    //验证码发送
    var countdown = 60;
    function settime(obj) { //发送验证码倒计时
        if (countdown == 0) {
            obj.attr('is_allow_click', 1);
//            obj.attr('disabled', false);
            //obj.removeattr("disabled"); 
            obj.text("获取验证码");
            countdown = 60;
            return;
        } else {
            obj.attr('is_allow_click', 0);
//            obj.attr('disabled', true);
            obj.text("重新发送(" + countdown + ")");
            countdown--;
        }
        setTimeout(function () {
            settime(obj)
        }, 1000);
    }
</script>
{/block}